import Toast from '@vant/weapp/toast/toast'
import api from '../../api/api'
Page({
  data: {
    phone: '',
    password: ''
  },
  back() {
    wx.navigateBack()
  },
  toHome() {
    wx.switchTab({
      url: '/pages/home/home',
    })
  },
  async findPwd(e) {
    let phone = e.detail.value.phone
    let password = e.detail.value.password
    const rulePhone = /^1[3-9]\d{9}$/
    const rulePassword = /^[A-Za-z][A-Za-z\d]{5,15}$/
    if (phone == '') {
      Toast.fail('手机号不能为空')
      return
    }
    if (!rulePhone.test(phone)) {
      Toast.fail('手机号格式错误')
      return
    }
    if (password == '') {
      Toast.fail('密码不能为空')
      return
    }
    if (!rulePassword.test(password)) {
      Toast.fail('密码格式错误')
      return
    }
    const res = await api.retrievePassword({ phone, password })
    console.log('找回密码', res)
    if (res.data.code == 'L001') {
      Toast.success(res.data.msg)
      setTimeout(() => {
        wx.redirectTo({
          url: '/pages/login/login',
        })
      }, 1500)
    } else {
      Toast.fail(res.data.msg)
    }
  },
  onLoad(options) {

  },
  onShow() {

  },
})